//全局设置axios
axios.defaults.baseURL='http://192.168.31.61:7801/user';
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
Vue.prototype.$http = axios;
var PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz93XIzimWfOzID0sMCz39s59TFwqbM7Q3L/t6JKY3MeoxtOInoruzc6PfblkkqdzoP6P/eLhk6dt4SEz/HlCX3JaqZqk8Nh+MMyD7rRWe1FXWkmseMqB2HqYW2b07KCyJcwg2tFQuwllmzIxtdM0Z1tgU7rKfw0utDNjpQa1avv3euagSCzvbmb8Qe49UkhDAbWf1OZDFMBZ56Mj1eaQv0s80LgbUlvMy87iujVE2sJyAklM2JtkK0VhHphMUPHW6GEr862iNC2Hm8YNraeubOXMJIgaaooml9O7rkltETU7MhjOm09ezpEt8c+P0hs27chlbi2LzS57GxDZwxmQTQIDAQAB";

//解析url参数函数
function parseParamObj(url) {
    let paramsStr = url.substring(url.indexOf("?")+1); //typeId=27
    let paramsArray = paramsStr.split("&"); //typeId=27 xxx=xxx
    let paramObj = {};
    $.each(paramsArray,function(index,param){
        let parmName = param.split("=")[0];
        let parmValue = param.split("=")[1];
        paramObj[parmName] = parmValue;
    })
    return paramObj;
}

function RsA_encryption(jsonData){
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----\n'+ PUBLIC_KEY + '\n-----END PUBLIC KEY-----');
    return encrypt.encryptLong(JSON.stringify(jsonData));
}

/*
  axios的前置请求拦截器
*/
axios.interceptors.request.use(config=>{
        // console.log(config)
        if (localStorage.getItem("token")){
            config.headers.TOKEN = localStorage.getItem("token");
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    })
/*
  axios的响应请求拦截器
    config:就是当前的响应对象
*/
axios.interceptors.response.use(config=>{
        if (!(config.data.success) && config.data.msg === "void"){//同时让success和data作为判断条件
            location.href = "clear.html";
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    })

